/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.anism.holidays.sessionbeans;

import java.util.Date;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.anism.holidays.entities.Employee;
import org.anism.holidays.entities.HolidayRequests;
import org.anism.holidays.facades.HolidayRequestsFacadeLocal;

/**
 *
 * @author user
 */
@Stateless
public class HolidayInput implements HolidayInputLocal {
    
    @EJB
    private HolidayRequestsFacadeLocal facade;
    
    @EJB
    private Authentication auth;
    
    @Override
    public Employee authenticate(final String employeeId, final String password) {
        return auth.authenticate(employeeId, password);
    }

    @Override
    public HolidayRequests addHolidayRequest(Employee employee, Date startDate, Date endDate, String type) {
        HolidayRequests holidayRequest = new HolidayRequests();
        holidayRequest.setEmployee(employee.getId());
        holidayRequest.setStartDate(startDate);
        holidayRequest.setEndDate(endDate);
        
        // TODO: table holidaytypes, puis aller chercher le type en base, et créer la holidayrequest
        // à la fin, retourner la nouvelle holidayrequest, avec le status created
        
        holidayRequest.setType(Integer.parseInt(type));
        
        facade.create(holidayRequest);
        
        return holidayRequest;
    }
    
}
